<%-- 
    Document   : userManager
    Created on : 2016-6-30, 19:42:14
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="${base}/css/bootstrap-datetimepicker.min.css"/>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.min.js" ></script>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.zh-CN.js" ></script>
    </head>
    <style>
        .error{font-size: 1px; color: red}
    </style>

    <body ng-app="userManage" ng-controller="mainCtrl" style="padding-top: 10px;">

        <!--        <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理列表</strong> / <small>User list</small></div>
                </div>-->
        <!--        <hr>-->

        <div class="col-lg-12">
            <div class="panel panel-default" style="overflow: hidden">

                <div class="panel-heading"><span style="float: left">样本采集列表</span>
                    <div>
                        <input ng-model="searchContent"  placeholder="名字/ID" style="width:320px; float: left;margin-left: 20px" class="form-control input-sm" />
                        <button ng-click="getUsers()" style="float: left" class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>
                        <button ng-click="addUser()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-send"></span>&nbsp;&nbsp;添加</button>
                        <button ng-click="getUsers()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-refresh"></span>&nbsp;&nbsp;刷新</button></div>


                    <div style="clear: both"></div>
                </div>    
            </div>

            <table class="table table-striped table-bordered  table-hover ">
                <thead>
                    <tr>
                        <!--                        <th><input type="checkbox" ng-model="checkAll" ng-change="checked()"></th>-->
                        <th class="table-id">样本号</th>
                        <!--                        <th class="table-id">病人ID</th>-->
                        <th class="table-title">病人姓名</th>
                        <th class="table-type">性别</th>
                        <!--                        <th class="">电话</th>-->
                        <th class="table-author am-hide-sm-only">年龄</th>
                        <th class="table-date am-hide-sm-only">类型</th>

                        <th class="table-set">样本</th>
                        <th class="table-set">送检医生</th>
                        <th class="table-set">送检时间</th>
                        <th class="">项目</th>

                        <th class="">其他</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="list in lists" >
                     
                        <td>{{list.SAMPLENO}}</td>
                        <!--                        <td>{{list.PATIENTID}}</td>-->
                        <td>{{list.PATIENTNAME}}</td>
                        <td>{{list.SEX}}</td>
                        <!--                        <td class="am-hide-sm-only">{{list.PHONENO}}</td>-->
                        <td class="am-hide-sm-only">{{list.AGE}}</td>
                        <td class="am-hide-sm-only">{{list.STAYHOSPITALMODE}}</td>
                       
                        <td class="am-hide-sm-only">{{list.SAMPLE}}</td>
                        <td class="am-hide-sm-only">{{list.SJYS}}</td>
                        <td class="am-hide-sm-only">{{list.CUSTOM1}}</td>
                        <td class="am-hide-sm-only">{{list.EXAMINAIM}}</td>
                      
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                     <button ng-click="deleteInfo(list)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>&nbsp;删除</button>

                                </div>
                            </div>
                        </td>
                    </tr>

                </tbody>
            </table>
            <footer class="panel-heading">
                <div class="row">
                    <div style="text-align: center" >                
                        <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="page.currentPage" items-per-page="page.pageSize" total-items="page.bigTotalItems" ng-model="page.bigCurrentPage" max-size="page.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                    </div>
                </div>
            </footer>

        </div>

    </div>


    <!--<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>-->

    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="myModal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">


                <!--  <label name="email">Your email</label>
                  <input type="email" name="email" ng-model="email" placeholder="Email Address" />-->

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="deteleInfo()"><span aria-hidden="true">&times;</span></button>
                    <h3 class="modal-title" id="myModalLabel" style="text-align:center ;">{{title}}样本</h3>
                </div>
                <div class="modal-body">
                    <form name="form" class="form-validation"> 
                        <table  class="cx-table">

                            <tr>
                                <td>病历号:</td>
                                <td>
                                    <div style="position: relative;">
                                        <input type="text" class="form-control " id="zyh" ng-model="data.PATIENTID" ng-keydown="searchPatientId($event)" >
                                        <a ng-click="searchPid()"><i style="position: absolute;right: 2px; top: 10px;" class="fa fa-search"></i></a>
                                    </div>
                                </td>
                                <td>设备:</td>
                                <td>
                                    <select  class="form-control" ng-change="changeSelect(selectdDevice)" ng-model="selectdDevice" ng-options="x as (x.DEVICEMODEL +       x.DEVICENAME) for x in pdts"></select>

                                </td>
                                <td>样本号:</td>
                                <td><input type="text" class="form-control"  ng-model="data.SAMPLENO"></td>

                            </tr>

                            <tr>
                                <td>姓名:</td>
                                <td>
                                    <div style="position: relative;">
                                        <input type="text" class="form-control"  ng-model="data.PATIENTNAME">
                                        <a ><i style="position: absolute;right: 2px; top: 10px; color: red" >*</i></a>
                                    </div>
                                </td>
                                <td>性别:</td>
                                <td>
                                    <div style="position: relative;">
                                        <select  class="form-control"  ng-model="data.SEX">
                                            <option ng-repeat="sex in sexs" value="{{sex.nan}}">{{sex.nan}}</option>
                                        </select>
                                        <a ><i style="position: absolute;right: 2px; top: 10px; color: red" >*</i></a>
                                    </div>
                                </td>
                                <td>年龄:</td>
                                <td>
                                    <div style="position: relative;">
                                        <input type="text" ng-model="data.AGE" class="form-control">
                                        <a ><i style="position: absolute;right: 2px; top: 10px; color: red" >*</i></a>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>送检医生:</td>
                                <td><input type="text" class="form-control"  ng-model="data.SJYS"></td>
                                <td>送检时间:</td>
                                <td><input type="text" ng-model="data.CUSTOM1" class="form-control"></td>
                                <td>类型:</td>
                                <td>
                                    <select  class="form-control"  ng-model="data.STAYHOSPITALMODE">
                                        <option ng-repeat="l in lxs" value="{{l.lx}}">{{l.lx}}</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>科室:</td>
                                <td><input type="text" class="form-control"  ng-model="data.SECTION"></td>
                                <td>样本:</td>
                                <td><select  class="form-control"  ng-model="data.SAMPLE">
                                        <option ng-repeat="yb in ybs" value="{{yb.SAMPLEDESCRIBE}}" >{{yb.SAMPLEDESCRIBE}}</option>
                                    </select>
                                </td>
                                <td>项目:</td>
                                <td>
                                    <input type="text" class="form-control"  ng-model="data.EXAMINAIM">

                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
                <div class="modal-footer" >
                    <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
                    <button type="button" class="btn btn-primary" ng-disabled="form.$invalid" ng-click="saveSample()" >保存</button>

                </div>
            </div>
        </div>

    </div>



    <div class="modal fade modal-info" id="mode4" role="dialog" aria-labelledby="gridSystemModalLabel">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">信息列表</h4>
                </div>
                <div class="modal-body">
                    <table class="table table-bordered table-striped">
                        <tr ng-dblclick="selectInfo(info)" ng-repeat="info in infos">
                            <td>{{info.PATIENTID}}</td>
                            <td>{{info.PATIENTNAME}}</td>
                            <td>{{info.SEX}}</td>
                            <td>{{info.AGE}}</td>
                            <td>{{info.EXAMINAIM}}</td>
                        </tr>
                    </table>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</body>
</html>
<script>
    var app = angular.module("userManage", ['baseModule', 'ui.validate', 'ui.select', 'ui.bootstrap']);
    app.controller("mainCtrl", function ($scope, base) {
        $scope.user = {};
        $scope.searchContent = "";
        $scope.data = {};
        $scope.page = {currentPage: 1};
        $scope.setPage = function (pageNo) {
            $scope.page.currentPage = pageNo;
        };
        $scope.pageChanged = function () {
            $scope.getUsers();
        };
        $scope.initData = function () {
            $scope.data = {};
            $scope.data.SEX = "男";
            $scope.data.CUSTOM1 = dateUtil.en();
        }

        $scope.page.maxSize = 10;
        $scope.page.bigTotalItems = 20;
        $scope.page.bigCurrentPage = 1;
        $scope.page.pageSize = 10;
        $scope.getUsers = function () {//显示用户信息
            base.post("spat/getUserList", {pageSize: $scope.page.pageSize, currentPage: $scope.page.currentPage, searchContent: $scope.searchContent}).get(function (data) {
                if (data) {
                    $scope.lists = data.list;
                    $scope.page.bigTotalItems = data.totalRow;
                    for (var i in  $scope.lists) {
                        if ($scope.lists[i].SEND_CENTER_STATUS == 0) {

                            $scope.lists[i].SEND_CENTER_STATUS_NAME = "未发送";

                        } else if ($scope.lists[i].SEND_CENTER_STATUS == 1) {
                            $scope.lists[i].SEND_CENTER_STATUS_NAME = "已发送";
                            $scope.lists[i].SEND_CENTER_STATUS_FLAG = true;
                        } else {
                            $scope.lists[i].SEND_CENTER_STATUS_NAME = "已获取";
                            $scope.lists[i].SEND_CENTER_STATUS_FLAG = true;
                        }

                        if ($scope.lists[i].RETURN_RESULT_FLAG == 0) {
                            $scope.lists[i].RETURN_RESULT_FLAG_NAME = "无结果";
                        } else {
                            $scope.lists[i].RETURN_RESULT_FLAG_NAME = "有结果";
                        }
                    }
                }
            })
        }
        $scope.getUsers();
        $scope.getKsmc = function () {
            base.post("spat/getKsmc", {}).get(function (data) {
                $scope.ksmcs = data;
                $scope.ksed = "输血科";
            });
        }
        $scope.getSampleType = function () {
            base.post("spat/getSampleType", {}).get(function (data) {
                $scope.ybs = data;
                $scope.ybed = "血浆";
            });
        }
        $scope.getLisDevices = function () {//仪器显示
            base.post("spat/getLisDevices").get(function (data) {
                // console.log(data);
                if (data) {
                    $scope.pdts = data;
//                     
                }
            })
        }
        $scope.searchPatientId = function (event) {
            if (event.keyCode == 13) {
                $scope.searchPid();
            }
        }
        $scope.searchPid = function () {
            if ($scope.data.PATIENTID) {
                base.post("spat/patInfoForHis", {PATIENTID: $scope.data.PATIENTID}).get(function (data) {
                    if (data != "false") {
                        if (data instanceof Array) {

                            if (data.length == 1) {
                                $scope.data = data[0];

                                $scope.patientpk = data.PK;
                            } else if (data.length > 1) {
                                $scope.infos = data;
                                $(".modal-info").modal('show');
                            }

                        } else {
                            $scope.info = data;
                            $scope.patientpk = data.PK;
                        }
                        //  $scope.$apply();
                    } else {
                        steveAl("没有找到病历号!", 1000);
                    }
                })
            }

        }
        $scope.selectInfo = function (info) {
            $scope.data = info;
            $(".modal-info").modal('hide');
        }
        $scope.sexs = [{nan: "男"}, {nan: "女"}];
        $scope.lxs = [{lx: "住院"}, {lx: "门诊"}, {lx: "体检"}];
        $scope.init = function () {
            $scope.initData();
            $scope.getSampleType();
            $scope.getKsmc();
            $scope.getLisDevices();
        }

        $scope.addUser = function () {//打开新增窗口
            $scope.title = "新增";
            $('#myModal').modal({
                show: true,
                backdrop: true
            })

            if ($scope.sample_code) {
                base.post("spat/getSampleNo", {code: $scope.sample_code}).get(function (data) {
                    if (data != "false") {
                        $scope.data.SAMPLENO = data;
                    }
                })
            }
        };
        $scope.saveSample = function () {
            var sex = $("#sex").val();
            var lx = $("#lx").val();
            if (!$scope.data.PATIENTNAME) {
                steveAl("请输入姓名！", 800);
            } else if (!$scope.data.SEX) {
                steveAl("请选择性别！", 800);
            } else if (!$scope.data.AGE) {
                steveAl("请输入年龄！", 800);
            } else {
                base.post("spat/saveInfo", $scope.data).get(function (data) {
                    if (data == "1") {
                        steveAl("样本号已经被使用", 1000);
                    } else if (data == "true") {
                        steveAl("保存成功", 1000);
                        $scope.getUsers();
                        $scope.initData();
                        $('#myModal').modal("hide");
                    }
                })
            }

        }


        $scope.deleteInfo = function (item) {
            steveConfrim("确定删除吗" + item.PATIENTNAME + "？", function () {
                base.post("spat/deleteInfo", {INFOPK: item.INFOPK, SAMPLENO: item.SAMPLENO}).get(function (data) {
                    if (data == 'true') {
                        $scope.getUsers();
                    } else {
                        steveAl("删除失败!", 1000);
                    }

                });
            });
        };
        $scope.init();
        var pl = [];
        $scope.printTM = function (list) {
            pl.splice(0, pl.length);
            pl.push(list);
            localStorage.pl = JSON.stringify(pl);
            window.open("printTM.jsp");
        }
        $scope.checked = function () {
            if ($scope.checkAll == true) {
                for (var i = 0; i < $scope.lists.length; i++) {
                    $scope.lists[i].check = true;
                }
            } else {
                for (var i = 0; i < $scope.lists.length; i++) {
                    $scope.lists[i].check = false;
                }
            }
        }



        $scope.changeSelect = function (item) {
            $scope.sample_code = item.NOTES;
            console.log(item);
            if (item.NOTES) {
                base.post("spat/getSampleNo", {code: $scope.sample_code}).get(function (data) {
                    if (data != "false") {
                        $scope.data.SAMPLENO = data;
                    }
                })
            }
            console.log(item);
        }



        $('#datetimepicker').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd ',
            startView: 3,
            autoclose: true,
            minView: 2
        }).on('changeDate', function (ev) {
            $scope.date = ev.date.Format("yyyy-MM-dd");
        });

    });




</script>
